<?php # Левое меню

class menu_left extends Load_use
{
	function getBlock()
	{
		$html = '';
		global $menu_page_ids;
		global $kvantis;
						
		foreach( $menu_page_ids as $page_id )
		$parents[$page_id] = '"#'.$page_id.'#"';
		$this->conn->query('SELECT `id`, `url`, `title`, `parents` FROM `pages` WHERE `parents` IN( '.implode( ',', $parents ).' ) AND templ = "_simple"');
		while( $row = $this->conn->fetch() )
			$sum_menu[$row->parents][] = array( 'id' => $row->id, 'url' => $row->url, 'title' => $row->title );

		$this->conn->query('SELECT `id`, `url`, `title` FROM `pages` WHERE `id` IN( '.implode( ',', $menu_page_ids ).' ) ');
		while( $row = $this->conn->fetch() )
		{
			$sub_html = $rarget = '';
			if( isset( $sum_menu['#'.$row->id.'#'] ) )
			{
				$sub_html .= '<ul>';
				foreach( $sum_menu['#'.$row->id.'#'] as $sub )
				{
					$url = '/'.$row->url.'/'.$sub['url'];
					$rarget_sub = '';
					if( array_key_exists( $sub['id'], $kvantis ) ) {	
						$rarget_sub = 'target="_blank"';		
						$url = 'http://kvantis.ru'.$kvantis[$sub['id']];
					}
					$sub_html .= '<li'.( ( $this->view->url == $sub['url'] ) ? ' class="selected"' : '' ).'><a '.$rarget_sub.' href="'.$url.'">'.$sub['title'].'</a></li>';
				}
				$sub_html .= '</ul>';
			}
			$url = '/'.$row->url;
			if( array_key_exists( $row->id, $kvantis ) ) {	
				$rarget = 'target="_blank"';		
				$url = 'http://kvantis.ru'.$kvantis[$row->id];
			}
			$html .= '<li'.( ( $row->url == $this->view->url || '/'.$row->url == $this->view->url_before ) ? ' class="selected"' : '' ).'>
						<span><a '.$rarget.' href="'.$url.'">'.$row->title.'</a></span>
						'.$sub_html.'
					 </li>';
		}
 		return '<ul class="sidebar__navi">
					'.$html.'
				</ul>';
	}
}